package com.gs.wechatdemo.adapter;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.gs.wechatdemo.R;
import com.gs.wechatdemo.adapter.base.BaseAdapter;
import com.gs.wechatdemo.adapter.base.BaseViewHolder;
import com.gs.wechatdemo.db.bean.ContactBean;
import com.gs.wechatdemo.util.DateUtil;

import java.util.List;

public class ChatAdapter extends BaseAdapter<ContactBean> {

    private Activity activity;

    public ChatAdapter(Activity activity, Context context, List<ContactBean> mData, int layoutId) {
        super(context, mData, layoutId);
        this.activity = activity;
    }

    @Override
    public void convert(BaseViewHolder holder, ContactBean item, int position) {
        holder.setText(R.id.tv_name, item.getName());
        holder.setText(R.id.tv_content, item.getContent() == null ? "" : item.getContent());
        holder.setText(R.id.tv_time, DateUtil.dateToString(item.getDate()));
        holder.setNineImg(activity,R.id.nine_img,item.getPhoto());
        if (item.getNum() == 0) {
            holder.setVisibility(R.id.tv_num, View.GONE);
        } else {
            int num = item.getNum();
            if (num > 99) {
                num = 99;
            }
            holder.setText(R.id.tv_num, String.valueOf(num), View.VISIBLE);
        }
    }
}
